package top.xunfong.knowledge.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import top.xunfong.common.core.domain.dto.BatchDTO;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import top.xunfong.knowledge.mapper.KnowledgeFileMapper;
import top.xunfong.knowledge.service.KnowledgeFileService;
import top.xunfong.knowledge.entity.KnowledgeFile;
import top.xunfong.knowledge.dto.KnowledgeFileDTO;
import top.xunfong.knowledge.dto.KnowledgeFileQueryDTO;
import top.xunfong.knowledge.vo.KnowledgeFileVO;
import top.xunfong.mybatis.core.page.PageDTO;
import top.xunfong.common.core.domain.R;
import top.xunfong.common.core.domain.TableDataInfo;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class KnowledgeFileServiceImpl extends ServiceImpl<KnowledgeFileMapper, KnowledgeFile>  implements KnowledgeFileService {
    /**
     * 新增
     *
     * @param dto
     * @return
     */
    @Override
    public R<?> insertKnowledgeFile(KnowledgeFileDTO dto) {
        KnowledgeFile entity = BeanUtil.copyProperties(dto, KnowledgeFile.class, "id");
        return save(entity) ? R.ok() : R.fail();
    }


    /**
     * 修改
     *
     * @param dto
     * @return
     */
    @Override
    public R<?> updateKnowledgeFile(KnowledgeFileDTO dto){
        KnowledgeFile entity = BeanUtil.copyProperties(dto, KnowledgeFile.class);
        return updateById(entity) ? R.ok() : R.fail();
    }

    /**
     * 批量删除
     *
     * @param dto
     * @return
     */
    @Override
    public R<?> deleteKnowledgeFile(BatchDTO<Long> dto) {
        List<Long> ids = dto.getData();
        if (CollUtil.isNotEmpty(ids)) {
            return removeByIds(ids) ? R.ok() : R.fail();
        }
        return R.ok();
    }

    /**
     * 列表查询
     *
     * @param dto
     * @return
     */
    @Override
    public TableDataInfo<KnowledgeFileVO> listKnowledgeFile(KnowledgeFileQueryDTO dto, PageDTO pageDTO) {
        return null;
    }

    /**
     * 单查询
     *
     * @param id
     * @return
     */
    @Override
    public R<KnowledgeFileVO> singleKnowledgeFile(Long id) {
        KnowledgeFile byId = this.getById(id);
        return R.ok(BeanUtil.copyProperties(byId, KnowledgeFileVO.class));
    }
}